package com.house.user.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.house.user.entity.User;
import com.house.user.entity.dto.UserQueryDTO;
import com.house.user.service.IUserService;

@Controller

public class UserController {

	@Autowired
	private IUserService userService;
	
	@RequestMapping(value="/saveOrUpdate")
	public @ResponseBody String  saveOrUpdate(User u) {
		userService.saveOrUpdate(u);
		return "ok";
	}
	
	@RequestMapping(value="login")
	public String login(UserQueryDTO userQueryDTO) {

         User user2 = userService.findOneByUserCode(userQueryDTO);
		 //System.out.println(user2.toString());
		  if(user2!=null&&user2.getPassword().equals(userQueryDTO.getPassword())) {
			  System.out.println(user2.toString());
			  return "WEB-INF/pages/success";
		  }
		
		  return "WEB-INF/pages/login";
		
	}
	@RequestMapping(value="tologin")
	public  String toLogin() {
		return "WEB-INF/pages/login";
	}
	
	@RequestMapping(value="loginout")
	public String loginout() {
		
		return "WEB-INF/pages/login";
	}
}
